package com.jhx.video.draftbox

import android.os.AsyncTask
import com.jhx.common.model.Video
import com.jhx.common.thirdparty.db.DBHelper

/**
 *
 * @author Jack 2018-03-07 19:03
 */
class DraftBoxPresenterImpl : Contract.DraftBoxPresenter() {

    override fun getCacheVideo() {
        val list = DBHelper.queryAll(Video::class.java)
        mView?.getVideoListSuccess(list)
    }

    override fun delVideo(vide: Video?, complete: (() -> Unit)?) {
        if(vide != null) {
            val task = object: AsyncTask<Void, String, Void>() {
                override fun doInBackground(vararg params: Void?): Void? {
                    DBHelper.delData(Video::class.java, vide)
                    return null
                }

                override fun onPostExecute(result: Void?) {
                    super.onPostExecute(result)
                    complete?.invoke()
                }

            }
            task.execute()
        }


    }

    override fun recycler() {
        mView = null
    }

}